package com.xiaoxiong.mami.dao.mapper;

import com.xiaoxiong.mami.dao.daomain.UserAddress;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface UserAddressMapper {
    @Delete({
        "delete from user_address",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into user_address (id, userId, ",
        "telephone, address, ",
        "receiver, status, gender, ",
        "updateTime, isDef, ",
        "createTime)",
        "values (#{id,jdbcType=BIGINT}, #{userId,jdbcType=VARCHAR}, ",
        "#{telephone,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, ",
        "#{receiver,jdbcType=VARCHAR}, #{status,jdbcType=BIT}, #{gender,jdbcType=VARCHAR}, ",
        "#{updateTime,jdbcType=TIMESTAMP}, #{isDef,jdbcType=BIT}, ",
        "#{createTime,jdbcType=TIMESTAMP})"
    })
    int insert(UserAddress record);

    @InsertProvider(type=UserAddressSqlProvider.class, method="insertSelective")
    int insertSelective(UserAddress record);

    @Select({
        "select",
        "id, userId, telephone, address, receiver, status, gender, updateTime, isDef, ",
        "createTime",
        "from user_address",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="userId", property="userId", jdbcType=JdbcType.VARCHAR),
        @Result(column="telephone", property="telephone", jdbcType=JdbcType.VARCHAR),
        @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
        @Result(column="receiver", property="receiver", jdbcType=JdbcType.VARCHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.BIT),
        @Result(column="gender", property="gender", jdbcType=JdbcType.VARCHAR),
        @Result(column="updateTime", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="isDef", property="isDef", jdbcType=JdbcType.BIT),
        @Result(column="createTime", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    UserAddress selectByPrimaryKey(Long id);

    @UpdateProvider(type=UserAddressSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(UserAddress record);

    @Update({
        "update user_address",
        "set userId = #{userId,jdbcType=VARCHAR},",
          "telephone = #{telephone,jdbcType=VARCHAR},",
          "address = #{address,jdbcType=VARCHAR},",
          "receiver = #{receiver,jdbcType=VARCHAR},",
          "status = #{status,jdbcType=BIT},",
          "gender = #{gender,jdbcType=VARCHAR},",
          "updateTime = #{updateTime,jdbcType=TIMESTAMP},",
          "isDef = #{isDef,jdbcType=BIT},",
          "createTime = #{createTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(UserAddress record);
}